package com.coffeeloversupportlibrary.core.base;
import android.util.Log;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModel;

/**
 * @author puyv
 * @createTime 2021/11/4 9:10
 * @projectName CoffeeLoverSupportLibrary
 * @className BaseViewModel.java
 * @description
 * 1.BaseViewModel 应该持有 BaseModel 引用，该变量对子类可见
 * 2.实现 IViewModel 具备生命周感知能力
 */
public abstract class BaseViewModel<M extends BaseModel> extends ViewModel implements IViewModel {

    protected M mModel;

    public BaseViewModel(){
    }

    protected abstract void setModel();




    /**
    * @date 2021/11/4 9:21
    * @params []
    * @return void
    * @description IViewModel 所提供的关于生命周期回调的一系列方法
    */

    @Override
    public void onCreate() {

    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }
    @Override
    public void onDestroy() {
        if(mModel != null){
            mModel.onDestroy();
            mModel = null;
        }
    }

    @Override
    public void onAny(LifecycleOwner owner, Lifecycle.Event event) {

    }

}
